package com.dean.ui.panel.impl;

import com.dean.service.DeanLogPrintService;
import com.dean.service.DeanLogThreadService;
import com.dean.ui.panel.DeanPanel;
import com.dean.ui.utils.UiUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.*;

/**
 * @ClassName DeanLogPanel
 * @Description 日志页面展示
 * @Author dean
 * @Date 2021/10/3 11:49
 */
public class DeanLogPanel implements DeanPanel {

    private final Logger logger = LoggerFactory.getLogger(DeanLogPanel.class);
    private  JPanel panel = null;

    private JTextArea exeLog = null;

    /**
     * 显示内容
     *
     * @return
     */
    @Override
    public JPanel showView() {
        panel = new JPanel();
        panel.setBounds(UiUtils.menuWidth, 0, UiUtils.contentWidth,UiUtils.noBorderHeight);
        panel.setBorder(BorderFactory.createLineBorder(Color.darkGray,1));
        panel.setLayout(null);

        exeLog = new JTextArea();
        JScrollPane logScrollPane = new JScrollPane(exeLog);
        logScrollPane.setBounds(UiUtils.elePadding, UiUtils.elePadding, UiUtils.contentWidth - UiUtils.elePadding*2, UiUtils.noBorderHeight);
        panel.add(logScrollPane);

        // 显示日志
        DeanLogPrintService deanLogPrint = new DeanLogPrintService(exeLog);
        deanLogPrint.setLastTimeFileSize(0L);
        logger.debug("当前线程池任务共{}个",DeanLogThreadService.getInstance().getQueue().size());
        DeanLogThreadService.getInstance().execute(deanLogPrint);
        return panel;
    }

    @Override
    public JScrollPane showScrollView() {
        return null;
    }
}
